$(function () {
    $(".divbg").hide();

    $("#bgtab").bootstrapTable({
        method:"post",
        contentType:'application/json',
        url:"/Kucun/aqkcpzbg",
        striped:true,
        pageNumber:1,
        pagination:true,
        sidePagination:'server',
        pageSize:3,
        pageList:[2,3,5,6],
        queryParams:function (parmes) {
            return{
                pageNum:(parmes.offset / parmes.limit) + 1,
                pageSize:parmes.limit,
            }
        },
        columns:[
            {title: "配置单编号",field: "storeId",align: "center"},
            {title:"产品编号",field:"productId",align:'center'},
            {title:"产品名称",field:"productName",align:'center'},
            {title:"I级分类",field:"firstKindName",align:'center'},
            {title:"II级分类",field:"secondKindName",align:'center'},
            {title:"III级分类",field:"thirdKindName",align:'center'},
            {title:"登记时间",field:"registerTime",align:'center'},
            {title: "变更",field: "id",align: "center",
                formatter:function (value,row,index) {
                    var a="<a href='#' onclick='aqkcbg("+JSON.stringify(row)+")'>变更</a>";
                    return a;
                }
            },
        ]
    })
})

function aqkcbg(row) {
    $("#aqkcdiv1").hide();
    $(".divbg").show();

    var date=new Date();
    var n=date.getFullYear();
    var y=date.getMonth()+1;
    var r=date.getDate();
    var s=date.getHours();
    var f=date.getMinutes();
    var m=date.getSeconds();
    var sj=n+"-"+y+"-"+r+" "+s+":"+f+":"+m;

    $("#fhsj").html(sj);

    let na = parent.document.getElementsByClassName("user_name")[0].innerHTML;

    $("#name").html(row.productName);
    $("#pzdbh").html(row.storeId);
    $("#bh").html(row.productId);
    $("#bjxx").val(row.minAmount);
    $("#bjsx").val(row.maxAmount);
    $("#ccl").val(row.maxCapacityAmount);
    $("#sjr").val(row.register);
    $("#djr").val(na);
    $("#comment").val(row.config);
    $("#djtime").html(sj);
}
function bgqd() {
    let bh=$("#pzdbh").html();
    let xx = $("#bjxx").val();
    let sx =  $("#bjsx").val();
    let sjr =  $("#sjr").val();
    let max =  $("#ccl").val();
    let ms =  $("#comment").val();


    if (xx>0) {
        if (parseInt(xx) < parseInt(sx)) {
            if (parseInt(sx) < parseInt(max)) {
                if (confirm("确定提交吗？")) {
                    let dx = {storeId: bh, minAmount: xx, maxAmount: sx, maxCapacityAmount: max, config: ms}
                    $.ajax({
                        type: "put",
                        contentType: "application/json;charset:utf-8",
                        url: "/Kucun/xgkc",
                        data: JSON.stringify(dx),
                        dataType: "json",
                        async: true,
                        success: function (data) {
                        }
                    })
                }

                $('#bgtab').bootstrapTable('refresh');
                $("#aqkcdiv1").show();
                $(".divbg").hide();

            } else {
                alert("最大储存量必须高于报警上限")
            }
        } else {
            alert("报警上限必须高于报警下限")
        }
    }
}
